DM 'CLEAR LOG; CLEAR OUTPUT;';
title '                      ';

/**********************************************************************************/
/**COMPUTE TABLE 3 for industry-level agreements*************************************/

/*BASE_NEGO_EXTENSION_RTT_FIN contains all industry-wage agreements and their date of effects*/

proc contents data=BASE_NEGO_EXTENSION_RTT_FIN short;
run;
/*main variables
ANNEE_ACCORD: year of agreement
ANNEE_EFFET: year of effect
MOIS_ACCORD: month of agreement
MOIS_EFFET: month of effect
IDCC2: industry code*/

/*delete duplicated observations*/
proc sort data=BASE_NEGO_EXTENSION_RTT_FIN out=hors_doubles_acc_eff nodupkeys;
by idcc2 annee_accord mois_accord annee_effet mois_effet ; run;
data duree_acc_eff;
set hors_doubles_acc_eff;
if mois_accord=. then delete;
if mois_effet=. then delete;
run;
/*Compute duration between date of wage agreement and date of effect (this variable is called dur_acc_eff)*/
data duree_acc_eff;
set duree_acc_eff;
dur_acc_eff=(annee_effet-annee_accord)*12+(mois_effet-mois_accord);
run;

proc sort data=duree_acc_eff out=test_br;
by idcc2 jour_accord mois_accord annee_accord;
run;
/*create dummy for second effect of the agreement*/
data test_br;
set test_br;
indic_2e=0;
l_idcc=lag(idcc2);
l_j=lag(jour_accord);
l_m=lag(mois_accord);
l_a=lag(annee_accord);
if l_idcc=idcc2 and l_j=jour_accord and l_m=mois_accord and l_a=annee_accord then indic_2e=1;
run;
/*create dummy for third effect of the agreement*/
data test_br;
set test_br;
indic_3e=0;
l_indic2e=lag(indic_2e);
if l_idcc=idcc2 and l_j=jour_accord and l_m=mois_accord and l_a=annee_accord and l_indic2e=1 then indic_3e=1;
run;
/*create dummy for fourth effect of the agreement*/
data test_br;
set test_br;
indic_4e=0;
l_indic3e=lag(indic_3e);
if l_idcc=idcc2 and l_j=jour_accord and l_m=mois_accord and l_a=annee_accord and l_indic3e=1 then indic_4e=1;
run;

/*create dummy for first effect of the agreement*/
data test_br;
set test_br;
if indic_3e=1 then indic_2e=0;
if indic_4e=1 then indic_3e=0;
indic_1e=1-indic_2e-indic_3e-indic_4e;
run;

/************TABLE 3 industry-level agreements***************/
/*proportion of agreements with one, two, three effects*/
proc freq data=test_br;
tables indic_1e indic_2e indic_3e indic_4e;
run;

/*statistics for duration between agreement and the first effect*/
proc univariate data=test_br(where=(indic_1e=1));
var dur_acc_eff;
run;
/*statistics for duration between agreement and the second effect*/
proc univariate data=test_br(where=(indic_2e=1));
var dur_acc_eff;
run;
/*statistics for duration between agreement and the third effect*/
proc univariate data=test_br(where=(indic_3e=1));
var dur_acc_eff;
run;
proc univariate data=test_br(where=(indic_4e=1));
var dur_acc_eff;
run;



/*************************TABLE 3 Firm-level agreements************/
/******computation of duration between agreements and effects at the firm level
asign=year of agreement
msign=month of agreement
ag1=year of first effect
mg1=month of first effect
ag2=year of first effect
mg2=month of first effect
ag3=year of first effect
mg3=month of first effect*/
data base_stat_corr5; set base_stat_corr5;
duree_acceff1=(ag1-asign)*12+(mg1-msign);
duree_effet21=(ag2-ag1)*12+(mg2-mg1);
duree_effet32=(ag3-ag2)*12+(mg3-mg2);
duree_effet31=(ag3-ag1)*12+(mg3-mg1);
run;

data test;
set base_stat_corr5;
duree_acceff2=duree_acceff1+duree_effet21;
duree_acceff3=duree_acceff1+duree_effet21+duree_effet32;
run;
/************TABLE 3 industry-level agreements***************/
/*statistics for duration between agreement and the first, second and third effects*/
proc univariate data=test; 
var duree_acceff1 duree_acceff2 duree_acceff3; run;
